package exercises.examples.eg_4;

public class Company {
    static String city;
    String company;

    public static void main(String[] args) {
        Company c1=new Company();
        Company c2=new Company();
        c1.city="Shanghai";
        c1.company="China Telecom";
        c2.city="Beijing";
        c2.company="China Mobile";
        System.out.println(c1.city+":"+c1.company);
        System.out.println(c2.city+":"+c2.company);
    }
    /*
    * output:
    * Beijing:China Telecom
    * Beijing:China Mobile
    *
    * reason: ln 12 changes the static variable city in class "Company"
    *   and references to variable "city" after ln 12 all get the value "Beijing"
    *   no matter which Company instance they are referencing
    *   therefore, the result by ln 10 is overwritten
    *   however, the variable "company" is stored along with individual instances, not the class
    *   hence changing the value of member "city" in ONE instance doesn't affect another
    *  */
}
